<!DOCTYPE html>
<html lang="{{ pagelng }}">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta content="{{ url_for('static', filename='favicon.png') }}" itemprop="image">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <title>{% block title %}{% block subtitle %}{% endblock %} - {{ _('Railgun') }}{% endblock %}</title>

    <!-- Stylesheets in head -->
    {% for s in g.scripts.headStyles() -%}
      <link href="{{ s }}" rel="stylesheet">
    {%- endfor %}

    <!-- Javascript libraries in head -->
    {% for s in g.scripts.headScripts() -%}
      <script src="{{ s }}" type="text/javascript" language="javascript"></script>
    {%- endfor %}
    {% block head %}{% endblock %}

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body{% block bodyattrs %}{% endblock %}>
    <!-- General navigation bar -->
    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">{{ _('Toggle navigation') }}</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="javascript: void(0);">{{ _('Railgun') }}</a>
        </div>
        <div class="collapse navbar-collapse">
          <!--
            Navigate links
            TODO: support multi-level navi items
          -->
          <ul class="nav navbar-nav">
            {%- macro show_navi_item(itm) -%}
              {% if current_user.is_admin or not itm.adminpage -%}
                {%- if not itm.has_child -%}
                <li{% if itm.is_active %} class="active"{% endif %}>
                  <a href="{{ itm.url }}">{{ itm.title }}</a>
                </li>
                {%- else -%}
                <li class="dropdown{% if itm.is_active %} active{% endif %}">
                  <a href="{{ itm.url }}" class="dropdown-toggle" data-toggle="dropdown">{{ itm.title }}</a>
                  <ul class="dropdown-menu" role="menu">
                    {%- for citm in itm.subitems %}
                      {% if current_user.is_admin or not citm.adminpage -%}
                        <li role="presentation"{% if citm.is_active %} class="active"{% endif %}>
                          <a role="menuitem" tabindex="-1" href="{{ citm.url }}">{{ citm.title }}</a>
                        </li>
                      {%- endif %}
                    {%- endfor %}
                  </ul>
                </li>
                {%- endif -%}
              {%- endif %}
            {%- endmacro -%}
            {%- for item in navibar %}
              {{ show_navi_item(item) }}
            {%- endfor %}
          </ul>
          <!-- Logged user info, or signup / signin links -->
          <ul class="nav navbar-nav navbar-right userinfo">
          {% if current_user.is_authenticated() -%}
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <img src="{{ current_user | gravatar }}" />
                {{ current_user.name }}
                <span class="caret"></span>
              </a>
              <ul class="dropdown-menu" role="menu">
                <li role="presentation">
                  <a role="menuitem" tabindex="-1" href="{{ url_for('profile_edit') }}">{{ _('Edit profile') }}</a>
                </li>
                <li role="presentation">
                  <a role="menuitem" tabindex="-1" href="{{ url_for('signout') }}">{{ _('Sign out') }}</a>
                </li>
              </ul>
            </li>
          {%- else -%}
            {% if allow_signup -%}
              <a class="btn btn-success navbar-btn" href="{{ url_for('signup') }}">{{ _('Sign up') }}</a>
            {%- endif %}
            <a class="btn btn-default navbar-btn" href="{{ url_for('signin') }}">{{ _('Sign in') }}</a>
          {%- endif %}
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <!-- General content area -->
    {% block wrapper -%}
    <div class="container" id="wrapper">
      <div class="content content-{{ request.endpoint | cssclass }}">
        <!-- Flashed messages -->
        <div class="flash-messages">
          {% for c, m in get_flashed_messages(with_categories=True) -%}
          <div class="flash flash-{{ c }} panel panel-{{ c }}">
            <div class="panel-heading">{{ m }}</div>
          </div>
          {%- endfor %}
        </div>
        {% block content %}{% endblock %}
      </div>
    </div>
    {%- endblock %}<!-- /.container -->

    <!-- Javascript libraries in tail -->
    {% for s in g.scripts.tailScripts() -%}
      <script src="{{ s }}" type="text/javascript" language="javascript"></script>
    {%- endfor %}
    {% block tail %}{% endblock %}
  </body>
</html>
